/***********************************************************************
 * Module:  SPIRoadSection.java
 * Author:  Administrator
 * Purpose: Defines the Class SPIRoadSection
 ***********************************************************************/

package ishitong.vehicleManagement.service.biz.impl;

import ishitong.vehicle.common.service.biz.SectionService;
import ishitong.commons.pagination.Pagination;
import ishitong.commons.pagination.PaginationResult;
import ishitong.vehicle.common.model.Section;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ishitong.platform.common.page.Page;

/** @pdOid 820807d5-9e27-4d7c-871b-589258ce4ea9 */
@Service(value = "spiRoadSectionService")
@Transactional
public class SPIRoadSectionService {
	/**
	 * @pdOid 66b0139d-faeb-4173-b915-d43924d6cb2a
	 * @pdRoleInfo migr=yes name=SectionService assc=association18
	 */
	@Autowired
	private SectionService sectionService;

	/**
	 * @param id
	 * @pdOid 328b4412-854c-472a-8f44-3f526496e758
	 */
	public Section findById(String id) {
		Section section = new Section();
		section.setId(Long.valueOf(id));
		List<Section> lstSection = sectionService.getSectionByCondition(section);
		if (lstSection.size() > 0) {
			section = lstSection.get(0);
			return section;
		}
		return null;
	}

	/**
	 * @param section
	 * @exception IllegalAccessException
	 * @exception InvocationTargetException
	 * @pdOid ccfa8ed3-be96-4284-a888-09051f03b02f
	 */
	public List<Section> findByQuery(Section section) throws IllegalAccessException, InvocationTargetException {
		List<Section> lstSection = sectionService.getSectionByCondition(section);
		return lstSection;
	}

	/**
	 * @param section
	 * @param pagination
	 * @pdOid a58d43cd-605f-457f-8ffe-40f416987118
	 */
	public Page<Section> findPage(Section section, Pagination pagination) {
		PaginationResult<Section> pr = sectionService.queryForPage(section, pagination);
		pagination = pr.getPagination();
		Page<Section> page = null;
		if (pagination != null) {
			page = new Page<Section>(pagination.getCurrentPage(), pagination.getPageSize(), pagination.getTotalRows(), pr.getResults());
		}
		return page;
	}

	/**
	 * @param id
	 * @pdOid 64c5d2a7-dfbc-4d69-b084-58e43a8f0fb1
	 */
	public void deleteSectionById(String id) {
		sectionService.deleteSectionByID(Long.valueOf(id));
	}

	/**
	 * @param section
	 * @pdOid 6bd1506a-00df-447a-a08c-49b732f3f05c
	 */
	public void saveSection(Section section) {
		if (section.getId() != null) {
			sectionService.updateSectionByID(section);
		} else {
			sectionService.addSection(section);
		}
	}

}